#ifndef _IFEXPRESSION_HPP
#define _IFEXPRESSION_HPP

#include <string>
#include "Token.hpp"
#include "Expression.hpp"
#include "BlockStatement.hpp"

namespace ast {
	
	class IfExpression : public Expression {
	public:
		IfExpression(TOKEN token) {
			_token = token;
		}
		virtual void ExpressionNode() override {}

		virtual string tokenLiteral() override {
			return _token._literal;
		}

		//if(a){...}
		//if(a){...} else{...}
		virtual string String() override {
			string out;
			string tab = "    ";
			for (int i = 0; i < _depth; i++) {
				out.append(tab);
			}
			out.append(_token._literal + " (");
			out.append(_condition->String() + ") ");
			out.append("{\n");
			_depth++;
			out.append(_consequence->String());	
			for (int i = 0; i < _depth - 1; i++) {
				out.append(tab);
			}
			out.append("}\n");
			if (_alternative != nullptr) {
				for (int i = 0; i < _depth - 1; i++) {
					out.append(tab);
				}
				out.append("else {\n");
				out.append(_alternative->String());
				for (int i = 0; i < _depth - 1; i++) {
					out.append(tab);
				}
				out.append("}");
			}
			_depth--;
			return out;
		}

		virtual ~IfExpression() {
			if (_condition != nullptr) {
				delete _condition;
			}
			if (_consequence != nullptr) {
				delete _consequence;
			}
			if (_alternative != nullptr) {
				delete _alternative;
			}
		}

	public:
		TOKEN _token;
		Expression* _condition{ nullptr };
		BlockStatement* _consequence{ nullptr };
		BlockStatement* _alternative{ nullptr };
	};
}

#endif